# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
from mindspore import Tensor

# print(Tensor(0.1))
# print(Tensor([1,3,5]))
# print(Tensor([[1,2],[2,3],[5,7]]))
# print(type(Tensor(0.1)))
# print(type(Tensor([1,3,5])))
# print(type(Tensor([[1,2],[2,3],[5,7]])))
import numpy as np
# array=np.array([1,0,2,5])
# tensor_arr=Tensor(array)
# print(type(array))
# print(type(tensor_arr))
from mindspore import set_seed
from mindspore import dtype as mstype
from mindspore.common.initializer import One, Normal
# t1=Tensor(shape=(2,2),dtype=mstype.float32,init=One())
# t2=Tensor(shape=(2,3),dtype=mstype.float32,init=Normal())
# print(t1)
# print(t2)
from mindspore import ops

# x = Tensor(np.array([[0.5, 1], [2.3, 1]]).astype(np.int32))
# output = ops.ones_like(x)
#
# print(x)
# print(output)
# print(x.shape)
# print(output.shape)
from mindspore import dtype as mstype

# shape=(2,2)
# ones=ops.Ones()
# output=ones(shape,mstype.float32)
# print(output)

# zeros=ops.Zeros()
# out=zeros(shape,mstype.float32)
# print(out)
# tensor=Tensor(np.array([[0,1],[2,3]]).astype(np.int32))

# print(tensor[0])
# print(tensor[1,1])
# print(tensor[:,-1])
# print(tensor[..., 0])
# x=Tensor(np.array([[1,2],[3,4]]),mstype.float32)
# print(x)
# print(x.shape)
# print(x.dtype)
# print(x.T)
# print(x.itemsize)
# print(x.nbytes)
# print(x.ndim)
# print(x.size)
# print(x.strides)

# x=Tensor(np.array([1,2,3]),mstype.float32)
# y=Tensor(np.array([4,5,6]),mstype.float32)
# print(x+y)
# print(x - y)
# print(x * y)
# print(y / x)
# print(y % x)
# print(y // x)
# zeros = ops.Zeros()
# output = zeros((2, 2), mstype.float32)
# print(type(output))
#
# n_out=output.asnumpy()
# print(type(n_out))
# arr=np.array([1,2,3])
# print(type(arr))
#
# t_out=Tensor(arr)
# print(type(t_out))
import h5py as h5
import os

if os.path.exists("./data"):
    pass
else:
    os.makedirs("./data")
tensor = Tensor(np.reshape(np.arange(16), (4, 4)))
# print(tensor)

filepath = "./data/tensor.hdf5"
f = h5.File(filepath, 'w')
dset = f.create_dataset('matrix', data=tensor.asnumpy())
f.close()

filepath = "./data/tensor.hdf5"
f = h5.File(filepath, 'r')
dset = f['matrix']
tensor_ = dset[:2]

print(type(tensor_))
tensor_r = Tensor(tensor_)
print(tensor_r)
